<beans:beans xmlns="http://www.springframework.org/schema/security"
	xmlns:beans="http://www.springframework.org/schema/beans"
	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:mongo="http://www.springframework.org/schema/data/mongo"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
	http://www.springframework.org/schema/security
	http://www.springframework.org/schema/security/spring-security-3.2.xsd
	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
	http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd">


	<context:component-scan base-package="com.ericsson.eritask" />
	
	
	<!-- EntityManagerFactory -->
  <beans:bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
    <beans:property name="persistenceUnitName" value="persistenceUnit"/>
    <beans:property name="dataSource" ref="dataSource"/>
    <!-- <beans:property name="persistenceUnitManager">
    	<beans:bean class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager" > 
    		<beans:property name="dataSource" ref="dataSource"/>
    	</beans:bean>
    </beans:property> -->
  </beans:bean> 
	
  <!-- MySQL Datasource with Commons DBCP connection pooling -->		
  <beans:bean class="org.apache.commons.dbcp.BasicDataSource" id="dataSource">
    <beans:property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <beans:property name="url" value="jdbc:mysql://localhost:3306/taskDB"/>
    <beans:property name="username" value="root"/>
    <beans:property name="password" value="root"/>
  </beans:bean>	
  
  <!-- Transaction Manager -->
  <beans:bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
    <beans:property name="entityManagerFactory" ref="entityManagerFactory"/>
  </beans:bean>
   
   
  <!-- Enable @Transactional annotation -->
  <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/> 



<beans:bean id="multipartResolver"
		class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
	<!-- mongo -->
	<mongo:mongo host="localhost" port="27017"></mongo:mongo>
	<mongo:db-factory host="localhost" port="27017" id="mongoDbFactory" dbname="ssdb" />	
	<mongo:mapping-converter  id="converter"  db-factory-ref="mongoDbFactory" />
	<beans:bean name="gridFsTemplate"
		class="org.springframework.data.mongodb.gridfs.GridFsTemplate">
		<beans:constructor-arg ref="mongoDbFactory" />
		<beans:constructor-arg ref="converter" />
	</beans:bean>
	
	<beans:bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
		<beans:constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
	</beans:bean>
<debug/>
	<!-- enable use-expressions -->
	<http auto-config="true">
	
	<!--  -->
	<intercept-url pattern="/login" access="IS_AUTHENTICATED_ANONYMOUSLY"  />
	<intercept-url pattern="/resources/**" access="IS_AUTHENTICATED_ANONYMOUSLY"  />	
	<intercept-url pattern="/**" access="ROLE_EMPLOYEE"  />	

		<!-- access denied page -->
		<access-denied-handler error-page="/403" />
		<form-login login-page="/login" 
			login-processing-url="/j_spring_security_check" username-parameter="username"
			password-parameter="password"
			authentication-success-handler-ref="taskAuthenticationSuccessHandler"/>
		<!-- <logout logout-success-url="/login?logout" /> -->
		<!-- enable csrf protection -->
		<!-- <csrf /> -->
	</http>

	<authentication-manager>
		<authentication-provider user-service-ref="myUserDetailSecurityService">
			<!-- <password-encoder hash="bcrypt" /> -->
		</authentication-provider>
	</authentication-manager>

</beans:beans>
